package com.qingke.xml.exerice;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

public class JaxbExample {

	public static void main(String[] args) {
		Student student = new Student("Qingke", "Male", 20);
		student.setId(001);
		Student student2 = new Student("qingke", "Male", 20);
		student.setId(002);
		Set<Student> students = new HashSet<Student>();
		students.add(student);
		students.add(student2);
		
		JAXBContext context;
		try {
			context = JAXBContext.newInstance(Student.class);
			Marshaller m = context.createMarshaller();
			for (Student stu: students) {
				m.marshal(stu, new File("student.xml"));
			}
			
//			Unmarshaller um = context.createUnmarshaller();
//			Object object = um.unmarshal(new File("student.xml"));
//			
//			if (object instanceof Student) {
//				Student student3 = (Student)object;
//				
//				System.out.println("Student3: " + student3);
//			}
//			
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}

}
